﻿using System.Collections.Generic;
using WCF.Common.DAL;

namespace WCF.Common
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“NorOpSv”。
    public class NorOpSv : INorOpSv
    {
        #region 用户表
        /// <summary>获取所有用户表的数据。</summary>
        /// <returns>返回用户清单。</returns>
        public List<UserObject> GetUsers()
        {
            return new UserObjectDAL().Gets();
        }
        /// <summary>插入用户数据。</summary>
        /// <param name="obj">要添加的用户信息。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult InsertUser(UserObject obj)
        {
            return new UserObjectDAL().Insert(obj);
        }
        /// <summary>删除用户数据。</summary>
        /// <param name="id">要删除用户信息的编号。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult DeleteUser(string id)
        {
            return new UserObjectDAL().Delete(id);
        }
        /// <summary>更新用户数据。</summary>
        /// <param name="obj">要添加的用户信息。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult UpdateUser(UserObject obj)
        {
            return new UserObjectDAL().Update(obj);
        }
        #endregion

        #region 角色表
        /// <summary>获取所有角色。</summary>
        /// <returns>返回角色清单。</returns>
        public List<RoleObject> GetRoles()
        {
            return new RoleObjectDAL().Gets();
        }
        /// <summary>添加一个新角色。</summary>
        /// <param name="role">要添加到角色信息。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult InsertRole(RoleObject role)
        {
            return new RoleObjectDAL().Insert(role);
        }
        /// <summary>删除一个角色信息。</summary>
        /// <param name="id">要删除角色信息的编号。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult DeleteRole(string id)
        {
            return new RoleObjectDAL().Delete(id);
        }
        /// <summary>更新一个角色信息。</summary>
        /// <param name="role">要更新的角色信息。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult UpdateRole(RoleObject role)
        {
            return new RoleObjectDAL().Update(role);
        }
        #endregion

        #region 应用表
        /// <summary>获取应用</summary>
        /// <returns>返回应用清单。</returns>
        public List<AppObject> GetApps()
        {
            return new AppObjectDAL().Gets();
        }
        /// <summary>添加一个新应用。</summary>
        /// <param name="obj">要添加的应用信息。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult InsertApp(AppObject obj)
        {
            return new AppObjectDAL().Insert(obj);
        }
        /// <summary>删除一个应用信息。</summary>
        /// <param name="id">要删除应用信息的编号。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult DeleteApps(string id)
        {
            return new AppObjectDAL().Delete(id);
        }
        /// <summary>更新一个应用信息。</summary>
        /// <param name="obj">要更新的应用信息。</param>
        /// <returns>操作结果信息。</returns>
        public OperateResult UpdateApp(AppObject obj)
        {
            return new AppObjectDAL().Update(obj);
        }
        /// <summary>根据应用编码查询应用实体</summary>
        /// <param name="code">要查询的应用编码。</param>
        /// <returns>返回应用信息。</returns>
        public AppObject SearchAppByCode(string code)
        {
            return new AppObjectDAL().SeachByCode(code);
        }

        #endregion

        #region 服务表
        /// <summary>获取所有服务表的数据。</summary>
        /// <returns>操作结果信息</returns>
        public List<ServiceObject> GetServices()
        {
            return new ServiceObjectDAL().Gets();
        }
        /// <summary>插入数据服务信息对象实例。</summary>
        /// <param name="obj"></param>
        /// <returns>操作结果信息</returns>
        public OperateResult InsertService(ServiceObject obj)
        {
            return new ServiceObjectDAL().Insert(obj);
        }
        /// <summary>删除数据服务信息对象实例。</summary>
        /// <param name="id"></param>
        /// <returns>操作结果信息</returns>
        public OperateResult DeleteService(string id)
        {
            return new ServiceObjectDAL().Delete(id);
        }
        /// <summary>更新数据服务信息对象实例。</summary>
        /// <param name="obj"></param>
        /// <returns>操作结果信息</returns>
        public OperateResult UpdateService(ServiceObject obj)
        {
            return new ServiceObjectDAL().Update(obj);
        }
        /// <summary>根据数据服务编码查询应用实体</summary>
        /// <param name="code">要查询的数据服务编码。</param>
        /// <returns>返回应用信息。</returns>
        public ServiceObject SearchServiceByCode(string code)
        {
            return new ServiceObjectDAL().SeachByCode(code);
        }
        #endregion

        /// <summary>插入用户组角色关联信息</summary>
        /// <param name="roleID"></param>
        /// <param name="userIDs"></param>
        /// <returns></returns>
        public OperateResult AssignUserRole(string roleID, string[] userIDs)
        {
            return new RelationUserRoleDAL().Assign(roleID,userIDs);
        }
        /// <summary>插入角色应用关联信息</summary>
        /// <param name="roleID"></param>
        /// <param name="appIDs"></param>
        /// <returns></returns>
        public OperateResult AssignRoleApp(string roleID, string[] appIDs)
        {
            return new RelationRoleAppDAL().Assign(roleID,appIDs);
        }
        /// <summary>插入角色服务关联信息</summary>
        /// <param name="roleID"></param>
        /// <param name="serviceIDs"></param>
        /// <returns></returns>
        public OperateResult AssignRoleService(string roleID, string[] serviceIDs)
        {
            return new RelationRoleServiceDAL().Assign(roleID, serviceIDs);
        }

        /// <summary>根据角色编号查询该角色包含的用户编号列表</summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public List<string> GetUserAuthoritys(string roleID)
        {
            return new RelationUserRoleDAL().GetByRoleID(roleID);
        }
        /// <summary>根据角色编号查询该角色包含的应用编号列表。</summary>
        /// <returns></returns>
        public List<string> GetAppAuthoritys(string roleID)
        {
            return new RelationRoleAppDAL().GetByRoleID(roleID);
        }
        /// <summary>根据角色编号查询该角色包含的数据服务编号列表。</summary>
        /// <param name="roleID"></param>
        /// <returns></returns>
        public List<string> GetServiceAuthoritys(string roleID)
        {
            return new RelationRoleServiceDAL().GetByRoleID(roleID);
        }
        
        public string GetParameter(string key)
        {
            return new ParameterDAL().Search(key);
        }

        public OperateResult UpdateParameter(string key, string value)
        {
            return new ParameterDAL().Update(key,value);
        }
        public OperateResult SetMapAutoload(string[] ids)
        {
            return new ServiceObjectDAL().SetAutoload(ids);
        }
        public OperateResult SetMapUnAutoload(string[] ids)
        {
            return new ServiceObjectDAL().SetUnAutoload(ids);
        }
    }
}